import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: const Text("Function Widget Demo"),
      ),
      body: SimpleDialogWidget(),
    ),
  ));
}

class SimpleDialogWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      child: const Text("对话框"),
      onPressed: () async {
        await _showLoadingDialog(context);
      },
    );
  }

  //  弹出对话框
  Future<void> _showLoadingDialog(BuildContext context) async{
    return showDialog(
      context: context,
      barrierDismissible: false,  //点击遮罩不关闭对话框
      builder: (BuildContext context) {
        return AlertDialog(
          content: Column(
            mainAxisSize: MainAxisSize.min,
            children: const <Widget>[
              CircularProgressIndicator(),
              Padding(
                padding: EdgeInsets.only(top: 26.0),
                child: Text("正在加载， 请稍后..."),
              ),
            ],
          ),
        );
      }
    );
  }
}
